package com.propic.www;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.List;

import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.FileImageOutputStream;


public class Copy {
	
	//去除list中的重复元素
    private static List<String> removeDuplicate(List<String> list)  
    {  
        HashSet<String> hashSet = new HashSet<String>(list);  
        list.clear();  
        list.addAll(hashSet);  
        return list;  
    }  
	
	public static void copyOne(List<String> path, String aimAdress) {
//		return null;
		List<String> trueList = removeDuplicate(path);
//		FileImageInputStream input = null;
		FileImageInputStream input = null;
		FileImageOutputStream output = null;
		for(String filename : trueList){
			try {
				input = new FileImageInputStream(new File(filename));
				output = new FileImageOutputStream(new File(aimAdress+"/"+new File(filename).getName()));
				int in = input.read();
				while(in!=-1){
					output.write(in);
					in=input.read();
				}
				input.close();
				output.close();
			}catch (FileNotFoundException e2){
				System.out.println("找不到指定文件");
				continue;
			}catch (IOException e1) {
				System.out.println("文件复制错误");
				continue;
			}catch (Exception e) {
				// TODO: handle exception
				System.out.println(e);
				continue;
			}
			System.out.println(new File(filename).getName()+"复制成功");
		}
	}

}
